package ywpt.service.people;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.stereotype.Service;

import ywpt.core.dao.HibernateEntityDao;
import ywpt.model.PeopleInfo;
import ywpt.model.PeopleTrain;
@Service("trainService")
public class TrainServiceImpl extends HibernateEntityDao<PeopleTrain> implements TrainService {

	@Override
	public PeopleTrain getTrainInfoById(Long id) {
		return this.get(id);
	}

	@Override
	public int getTrainInfoCountByCriteria(DetachedCriteria query) {
		return this.getCountByCriteria(query);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PeopleTrain> getTrainInfos(DetachedCriteria detachedCriteria,
			int pageSize, int startIndex) {
		return this.findAllByCriteria(detachedCriteria, pageSize, startIndex);
	}

	@Override
	public void removeTrainInfo(Long id) {
		this.removeById(id);
	}

	@Override
	public void saveTtrainInfo(PeopleTrain trainInfo,Long peopleId) {
		if(peopleId != null){
			trainInfo.setPeople(this.get(PeopleInfo.class, peopleId));
		}
		this.save(trainInfo);
	}

	@Override
	public void updateTrainInfo(PeopleTrain trainInfo,Long peopleId) {
		if(peopleId != null){
			trainInfo.setPeople(this.get(PeopleInfo.class, peopleId));
		}
		this.update(trainInfo);
	}

}
